package mall.promotion;

import mall.common.enums.PromotionTypeEnum;

import java.util.List;
import java.util.Set;

/**
 * 促销活动的通用父类
 * @author zmy
 */
public class PromotionBase {
    /** 活动 ID */
    private String promotionId;
    /** 活动名字 */
    private String name;
    /** 活动类型 */
    private String promotionType;
    /** 应用的商品 ID 集合 */
    private Set<String> productIds;
    /** 是否启用 */
    private boolean enabled;
    /** 优先级 */
    private int priority;

    public PromotionBase() {}

    public PromotionBase(String promotionId, String name, String promotionType, boolean enabled, int priority) {
        this.promotionId = promotionId;
        this.name = name;
        this.promotionType = promotionType;
        this.enabled = enabled;
        this.priority = priority;
    }

    public PromotionBase(String promotionId, String name, String promotionType, Set<String> productIds, boolean enabled, int priority) {
        this.promotionId = promotionId;
        this.name = name;
        this.promotionType = promotionType;
        this.productIds = productIds;
        this.enabled = enabled;
        this.priority = priority;
    }

    public String getPromotionId() {
        return promotionId;
    }

    public void setPromotionId(String promotionId) {
        this.promotionId = promotionId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPromotionType() {
        return promotionType;
    }

    public void setPromotionType(String promotionType) {
        this.promotionType = promotionType;
    }
    public void setPromotionType(PromotionTypeEnum typeEnum) {
        this.promotionType = typeEnum.type;
    }

    public boolean getEnabled() {
        return enabled;
    }

    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }

    public int getPriority() {
        return priority;
    }

    public void setPriority(int priority) {
        this.priority = priority;
    }

    public Set<String> getProductIds() {
        return productIds;
    }

    public void setProductIds(Set<String> productIds) {
        this.productIds = productIds;
    }

    /**
     * 新增活动的商品
     * @param pIds  要增加的商品id
     */
    public void addProduct(List<String> pIds) {
        productIds.addAll(pIds);
    }

    /**
     * 移除活动的商品
     * @param pIds  要移除的商品id
     */
    public void removeProduct(List<String> pIds) {
        pIds.forEach(productIds::remove);
    }

    @Override
    public String toString() {
        return "promotionId='" + promotionId + '\'' +
                ", name='" + name + '\'' +
                ", promotionType='" + promotionType + "(" + PromotionTypeEnum.getLabelByType(promotionType) + ")" + '\'' +
                ", productIds=" + productIds +
                ", enabled=" + enabled +
                ", priority=" + priority;
    }
}
